//==============================================================================
//
//               Copyright (C) 2005  Dick van Oudheusden
//  
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public
// License along with this program; if not, write to the Free
// Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
//==============================================================================
// 
//  $Date: 2005-05-05 07:12:19 $ $Revision: 1.2 $
//
//==============================================================================

#include <stdlib.h>
#include <math.h>

#include "ofc/DScore.h"

#include "DInc.h"
#include "DTest.h"


//-Datatype--------------------------------------------------------------------

void DScore_test(void)
{
  DScore    *sc1    = [DScore alloc];
  DScore    *sc2    = [DScore alloc];
  DScore    *sc3    = [DScore new];
  
  STARTTEST();

  TEST([sc3 length] == 0);
  
  TEST([sc3 range :0.0 :10.0]);

  TEST([sc3 min] == 0.0 );
  TEST([sc3 max] == 10.0);
  
  TEST([sc3 update :5.0] );
  TEST([sc3 update :10.0]);
  TEST([sc3 update :0.0 ]);
  TEST([sc3 update :9.5 ]);
  TEST([sc3 update :1.5 ]);
  
  TEST([sc3 length    ] == 5);
  TEST([sc3 sum       ] == 26.0);
  TEST([sc3 sumSquared] == 217.5);
  
  TEST(fabs([sc3 mean] - 5.20) < 0.01);
  TEST(fabs([sc3 standardDeviation] - 4.05709) < 0.00001);

  TEST([sc3 percentage] == 100.0);
  
  [sc3 distribution :25];
  
  TEST([sc3 percentage] == 20.0);
  
  [sc3 reset];
  TEST([sc3 length    ] == 0);
  TEST([sc3 sum       ] == 0.0);
  TEST([sc3 sumSquared] == 0.0);
  
  TEST([sc3 range :-100.0 :100.0]);
       
  [sc1 init :-10.0 :10.0];
  
  TEST([sc1 min] == -10.0);
  TEST([sc1 max] ==  10.0);
  
  [sc2 init :6];
  
  TEST([sc2 min] == 5.50);
  TEST([sc2 max] == 6.50);
  
  [sc3 free];
  [sc2 free];
  [sc1 free];
  
  STOPTEST();
}

